package com.sf.shiva.oms.jstorm.service.datasend.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sf.shiva.oms.jstorm.common.kafka.CustomKafkaProducer;
import com.sf.shiva.oms.jstorm.common.utils.ObjectMapperUtil;
import com.sf.shiva.oms.jstorm.service.datasend.SendKakfaService;

/**
 * 
 * 描述：发送kafka服务实现类
 *
 * <pre>HISTORY
 * ****************************************************************************
 *  ID   DATE           PERSON          REASON
 *  1    2018年4月3日      01369626         Create
 * ****************************************************************************
 * </pre>
 * @author 01369626
 * @since 1.0
 */
@Service
public class SendKafkaServiceImpl implements SendKakfaService{
    
    private static final Logger logger = LoggerFactory.getLogger(SendKafkaServiceImpl.class);
    
    @Autowired
    private CustomKafkaProducer customKafkaProducer;

    @Override
    public void send(Object object) {
        String msg = ObjectMapperUtil.toJson(object);
        try {
            customKafkaProducer.sendString(msg);
        }catch (Exception e) {
            logger.error("SendKafkaServiceImpl send message={}, error.", msg, e);
            //将发送失败的消息保存数据库或者其他操作，避免消息丢失
            //saveSendload(object);
        }
    }

}
